home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / M / May MacUser Program.cpt / miniGenApp Src / DocUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-29  |  3.5 KB  |  137 lines  |  [TEXT/KAHL]

  1. /* *****************************************************************************
  2.     FILE:             DocUtil.c
  3.     
  4.     DESCRIPTION:     Document Utilities 
  5.  
  6.     AUTHOR:            Kurt W.G. Matthies
  7.         
  8.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  9.     
  10.     Revision History:
  11.     ==========================================================
  12.     3.30.90    -    May 1990 MacUser Release
  13.     ==========================================================
  14.  
  15.    ***************************************************************************** */
  16. #include "AppGlobals.h"
  17.  
  18. #include "FileUtilPr.h"
  19. #include "MiscUtilPr.h"
  20. #include "WindowUtilPr.h"
  21. #include "DocUtilPr.h"
  22.  
  23.  
  24. /* ------------------------  Local Prototypes  --------------------------------- */
  25. DocPtr            createNewDoc        ( DocParamsPtr );
  26. DocPtr            allocDoc            ( void );
  27.  
  28. /* -----------------------------------------------------------------------------
  29.     doNewDoc -        open a new window
  30.     3.30.90kwgm
  31. -------------------------------------------------------------------------------- */
  32. Boolean
  33. doNewDoc ()
  34. {
  35.     DocParams            docParams;
  36.     DocPtr                theDoc;
  37.     Boolean                result;
  38.     
  39.     result = false;
  40.     
  41.     /*     
  42.         The DocParams data structure is used to tell the creation function
  43.         how to create the document and what file if any to associate
  44.         with the window
  45.     */
  46.     docParams.attributes = 0;
  47.     docParams.fileParams.fileName [0] = 0;
  48.     docParams.fileParams.openFileRefNum = 0;
  49.     docParams.fileParams.volRefNum = 0;
  50.  
  51.     if (theDoc = createNewDoc (&docParams))
  52.         result = true;
  53.  
  54.     return (result);
  55.  
  56. } /* doOpenDoc */
  57.  
  58. /* -----------------------------------------------------------------------------
  59.     doCloseDoc -    close the top document.
  60.     3.30.90kwgm
  61. -------------------------------------------------------------------------------- */
  62. Boolean
  63. doCloseDoc (theDoc)
  64.     WindowPtr            theDoc;
  65. {
  66.     ControlHandle        control;
  67.     Boolean                result;
  68.     WindowPtr            topWin;
  69.  
  70.     result = false;
  71.  
  72.     if (!theDoc)        /* nothing to close */
  73.         return (result);
  74.     
  75.     if (((WindowPeek) theDoc)->windowKind  < 1)    /* desk accessory */
  76.          CloseDeskAcc (((WindowPeek) theDoc)->windowKind);
  77.      /* close the file, then dispose of the window stuff */
  78.      else if ((result = closeDocFile (theDoc)) != kSaveChangeCancel)
  79.      {
  80.           while (control = ((WindowPeek)theDoc)->controlList)
  81.               DisposeControl (control);
  82.         
  83.         CloseWindow ((WindowPtr) theDoc);
  84.  
  85.         DisposPtr (theDoc);
  86.         result = true;
  87.     }
  88.     else
  89.         result = false;        /* the user canceled the close */
  90.  
  91.     return (result);
  92.     
  93. } /* doCloseDoc */
  94.  
  95. /*-------------------------------------------------------------------------
  96.     createNewDoc -    create a new document window
  97.     3.30.90kwgm
  98. --------------------------------------------------------------------------*/
  99. static DocPtr 
  100. createNewDoc (params)
  101.     DocParamsPtr        params;
  102. {
  103.     register DocPtr        theDoc;
  104.     Str255                title;
  105.  
  106.     if (!(theDoc = allocDoc ()))
  107.         return (0L);
  108.                 
  109.     GetIndString (title, kNameStrRsrc, kWindowTitleStrID);
  110.     
  111.     if (theDoc = NewWindow (theDoc, &gWindowRect, title, false, rDocProc, -1L, true, 0L))
  112.     {
  113.         ShowWindow (theDoc);
  114.         SelectWindow (theDoc);
  115.         SetPort (theDoc);
  116.     }
  117.  
  118.     return (theDoc);
  119.     
  120. } /* createNewDoc */
  121.  
  122. /* -----------------------------------------------------------
  123.     allocDoc -        allocate the document's data structs
  124.     3.30.90kwgm
  125. --------------------------------------------------------------  */
  126. static DocPtr
  127. allocDoc ()
  128. {
  129.     DocPtr        newDoc;
  130.         
  131.     return (newDoc = newClearPtr ((Size)sizeof (Doc)));
  132.         
  133. } /* allocDoc */
  134.  
  135. /* ===============================  EOF  =======================================
  136.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  137. ================================================================================ */